///*
// * Copyright © OpenAtom Foundation.
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *      http://www.apache.org/licenses/LICENSE-2.0
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
// * See the License for the specific language governing permissions and
// * limitations under the License.
// *
// */
//
//package io.iec.edp.caf.rpc.api.serialize;
//
//
//import io.iec.edp.caf.commons.core.SerializerFactory;
//import io.iec.edp.caf.commons.core.enums.SerializeType;
//import io.iec.edp.caf.commons.exception.CAFRuntimeException;
//
//import io.iec.edp.caf.commons.exception.entity.DefaultExceptionProperties;
//import io.iec.edp.caf.commons.exception.entity.ExceptionErrorCode;
//import io.iec.edp.caf.commons.exception.ExceptionLevel;
//import io.iec.edp.caf.commons.utils.InvokeService;
//import io.iec.edp.caf.rpc.api.common.GspSerializeType;
//import io.iec.edp.caf.rpc.api.entity.GspServiceReturnInfo;
//import io.iec.edp.caf.rpc.api.entity.RpcReturnValueDefinition;
//
//import io.iec.edp.caf.rpc.api.support.Type;
//import lombok.var;
//
//import java.util.concurrent.ConcurrentHashMap;
//
//public class ReturnValueSerializeUtil {
//
//    public String serializeReturnValue(
//            Object returnValue, GspServiceReturnInfo returnValueInfo) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
//
//        var serializeType = GspSerializeType.Json;
//        String customAssembly = "";
//        if (returnValueInfo != null) {
//            serializeType = returnValueInfo.getSerializeType();
//            customAssembly = returnValueInfo.getCustomClass();
//        }
//
//        String returnStr = "";
//        switch (serializeType) {
//            case Json:
//                returnStr = SerializerFactory.getDeserializer(SerializeType.Json).serializeToString(returnValue);
//                break;
//            case Custom:
//                returnStr = getCustomSerializeClass(customAssembly).serialize(returnValue);
//                //valueStr = type.GetMethod("Serialize").Invoke(instance, new[]{
//                break;
//            default:
//                throw new CAFRuntimeException(DefaultExceptionProperties.SERVICE_UNIT,
//                        DefaultExceptionProperties.RESOURCE_FILE,
//                        ExceptionErrorCode.serializeMethodNotSupport,
//                        new String[]{serializeType.toString()}, null, ExceptionLevel.Error, false);
//        }
//
//        return returnStr;
//    }
//
//    private ConcurrentHashMap<String, RpcCustomSerializer> customSerializersMap;
//
//    private RpcCustomSerializer getCustomSerializeClass(String implementClass) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
//        if (this.customSerializersMap == null) {
//            this.customSerializersMap = new ConcurrentHashMap<>();
//        }
//
//        RpcCustomSerializer rpcCustomSerializer = this.customSerializersMap.get(implementClass);
//
//        if (rpcCustomSerializer == null) {
//            rpcCustomSerializer = (RpcCustomSerializer) InvokeService.getClassByName(implementClass).newInstance();
//            this.customSerializersMap.put(implementClass, rpcCustomSerializer);
//        }
//
//        return rpcCustomSerializer;
//    }
//
//    public Object deSerializeReturnValue(Class clazz, String returnStr, RpcReturnValueDefinition returnValueInfo) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
//        return deSerializeReturnValue(new Type(clazz), returnStr, returnValueInfo);
//    }
//
//    public Object deSerializeReturnValue(Type type, String returnStr, RpcReturnValueDefinition returnValueInfo) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
//
//        var serializeType = GspSerializeType.Json;
//        String customAssembly = "";
//        if (returnValueInfo != null) {
//            serializeType = returnValueInfo.getSerializeType();
//            customAssembly = returnValueInfo.getSerializer();
//        }
//
//        Object returnValue;
//        switch (serializeType) {
//            case Json:
//                returnValue = SerializerFactory.getSerializer(SerializeType.Json).deserialize(returnStr, type.getRawType());
//                break;
//            case Custom:
//                returnValue = getCustomSerializeClass(customAssembly).deserialize(returnStr, type.getRawType());
//                //valueStr = type.GetMethod("Serialize").Invoke(instance, new[]{
//                break;
//            default:
//                throw new CAFRuntimeException(DefaultExceptionProperties.SERVICE_UNIT,
//                        DefaultExceptionProperties.RESOURCE_FILE,
//                        ExceptionErrorCode.serializeMethodNotSupport,
//                        new String[]{serializeType.toString()}, null);
//        }
//
//        return returnValue;
//    }
//}
